package com.shao.controller;

import com.shao.bean.loginBean;
import com.shao.bean.student;
import com.shao.common.R;
import com.shao.common.keyyy;
import com.shao.common.studentVo;
import com.shao.dao.stuLoginDao;
import com.shao.service.stuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: com.song shao
 * @date: 2022/2/26
 * @time: 20:09
 * @version: 1.0
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/stu")
public class stuController {

    @Autowired
    private stuService stu;

    @Autowired
    private stuLoginDao studao;

    /**
     * 查询当前学生的所有信息
     *
     * @param loginPeopel
     * @return
     */
    @PostMapping("/stuFindAll")
    public R<studentVo> stuFindAll(@RequestBody loginBean loginPeopel) {
        System.out.println(loginPeopel.toString());
        int states = loginPeopel.getStates();

        if (states == 0) {
            R r = stu.loginVerify(loginPeopel);
            Integer code = r.getCode();
            if (code == 1) {
                // 现在可以安心的查数据库返回数据了
                studentVo resule = stu.stuFindAll(loginPeopel);
                return R.success(resule);

            }
        }
        return R.error("你是来搞破坏的！你已被我抓住！");
    }

    /**
     * 教师查询学生信息
     *
     * @param loginPeopel
     * @return
     */
    @PostMapping("/teacherFindStudent")
    public R<studentVo> teacherFindStudent(@RequestBody keyyy loginPeopel) {
        student stas = studao.findStas(loginPeopel.getName());
        loginBean loginBean = new loginBean();
        loginBean.setName(loginPeopel.getName());
        loginBean.setStates(stas.getStu_state());
        loginBean.setPwd(stas.getStu_pwd());
        studentVo resule = stu.stuFindAll(loginBean);
        return resule != null ? R.success(resule) : R.error("你的网络有问题!");
    }
}
